package gui.nastaveni;

import gui.skolnikwin.SkolnikWinManager;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.border.Border;

import utils.Nastroje;

import model.UlohyEnum;

/**
 * Panel v ousku s vyberem uloh pro Matematiku.
 * @author schovjan
 * @date Jan 9, 2012
 */
public class CeskyJazykNastaveniPanel extends JPanel {

    private static final long serialVersionUID = 1L;
    private JCheckBox chbU = new JCheckBox("u/ů/ú");
    private JButton btnVyjmenovaSlovaVse = new JButton("Vše");
    private JButton btnVyjmenovaSlovaNic = new JButton("Nic");
    private JCheckBox chbB = new JCheckBox("B");
    private JCheckBox chbL = new JCheckBox("L");
    private JCheckBox chbM = new JCheckBox("M");
    private JCheckBox chbP = new JCheckBox("P");
    private JCheckBox chbS = new JCheckBox("S");
    private JCheckBox chbV = new JCheckBox("V");
    private JCheckBox chbZ = new JCheckBox("Z");


    /**
     * Konstruktor
     * @param winManager
     */
    public CeskyJazykNastaveniPanel(SkolnikWinManager winManager) {
	super();
	createGUI();
    }


    /**
     * Vytvoreni GUI
     */
    private void createGUI() {
	GroupLayout layout = new GroupLayout(this);
	layout.setAutoCreateGaps(true);
	layout.setAutoCreateContainerGaps(true);
	this.setLayout(layout);
	JPanel pVyjmSlova = new JPanel();
	GridBagLayout gbLayout = new GridBagLayout();
	GridBagConstraints gbConst = new GridBagConstraints();
	pVyjmSlova.setLayout(gbLayout);
	Border border = BorderFactory.createTitledBorder("Vyjmenovaná slova");
	pVyjmSlova.setBorder(border);
	pVyjmSlova.add(chbB);
	pVyjmSlova.add(chbL);
	pVyjmSlova.add(chbM);
	pVyjmSlova.add(chbP);
	pVyjmSlova.add(chbS);
	pVyjmSlova.add(chbV);
	pVyjmSlova.add(chbZ);
	gbConst.gridwidth = 2;
	gbConst.fill = GridBagConstraints.BOTH;
	gbConst.anchor = GridBagConstraints.CENTER;
	gbConst.gridx = 3;
	gbConst.gridy = 1;
	btnVyjmenovaSlovaVse.setFont(Nastroje.fMaly);
	btnVyjmenovaSlovaVse.addActionListener(new ActionListener() {

	    @Override
	    public void actionPerformed(ActionEvent arg0) {
		chbB.setSelected(true);
		chbL.setSelected(true);
		chbM.setSelected(true);
		chbP.setSelected(true);
		chbS.setSelected(true);
		chbV.setSelected(true);
		chbZ.setSelected(true);
	    }
	});
	pVyjmSlova.add(btnVyjmenovaSlovaVse, gbConst);
	gbConst.gridx = 5;
	gbConst.gridy = 1;
	btnVyjmenovaSlovaNic.setFont(Nastroje.fMaly);
	btnVyjmenovaSlovaNic.addActionListener(new ActionListener() {

	    @Override
	    public void actionPerformed(ActionEvent arg0) {
		chbB.setSelected(false);
		chbL.setSelected(false);
		chbM.setSelected(false);
		chbP.setSelected(false);
		chbS.setSelected(false);
		chbV.setSelected(false);
		chbZ.setSelected(false);
	    }
	});
	pVyjmSlova.add(btnVyjmenovaSlovaNic, gbConst);
		// shoda prisudku s podmetem
	JPanel pShodaPrisPodm = new JPanel();
	Border border2 = BorderFactory.createTitledBorder("Shoda přísudku s podmětem");
	pShodaPrisPodm.setBorder(border2);
		// pridani komponent na panel rozcestniku
	layout.setHorizontalGroup(layout.createSequentialGroup()
		.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
			.addComponent(pVyjmSlova, Alignment.CENTER)
			.addComponent(pShodaPrisPodm, Alignment.CENTER)
			));
	layout.setVerticalGroup(layout.createSequentialGroup()
		.addGroup(layout.createSequentialGroup()
			.addComponent(pVyjmSlova)
			.addComponent(pShodaPrisPodm)
			));
    }


    /**
     * Vrati zadani pro ulohu cestina
     * @return
     */
    public List<UlohyEnum> getZadaniUloh() {
	List<UlohyEnum> zadani = new ArrayList<UlohyEnum>();
	if (chbB.isSelected())
	    zadani.add(UlohyEnum.VS_B);
	if (chbL.isSelected())
	    zadani.add(UlohyEnum.VS_L);
	if (chbM.isSelected())
	    zadani.add(UlohyEnum.VS_M);
	if (chbP.isSelected())
	    zadani.add(UlohyEnum.VS_P);
	if (chbS.isSelected())
	    zadani.add(UlohyEnum.VS_S);
	if (chbV.isSelected())
	    zadani.add(UlohyEnum.VS_V);
	if (chbZ.isSelected())
	    zadani.add(UlohyEnum.VS_Z);
	
	if (chbU.isSelected())
	    zadani.add(UlohyEnum.uU);

	return zadani;
    }
}
